package com.totcy.atom.view.fragment;

import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.totcy.baselibrary.base.BaseMvpFragment;
import com.totcy.baselibrary.base.mvpbase.BasePresenterImpl;
import com.totcy.baselibrary.base.mvpbase.BaseView;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * description: fragment基类
 * author: Totcy
 * date: 2017/10/31 17:38
 * update: 2017/10/31
 */

public abstract class BaseFragment<V extends BaseView,P extends BasePresenterImpl> extends BaseMvpFragment<V,P> {

    private Unbinder unbinder;
    private String fragmentTitle;

    @Override
    protected View startInvoke(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View mView = inflater.inflate(getLayoutId(), container, false);
        unbinder = ButterKnife.bind(this, mView);
        initView(savedInstanceState);
        return mView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    public abstract
    @LayoutRes
    int getLayoutId();

    public abstract void initView(Bundle savedInstanceState);

    public String getFragmentTitle() {
        return fragmentTitle;
    }

    public BaseFragment setFragmentTitle(String fragmentTitle) {
        this.fragmentTitle = fragmentTitle;
        return this;
    }
}
